#ifndef ClassTree_First
#define ClassTree_First
#ifdef __GNUG__
#pragma interface
#endif

#include "TreeView.h"
#include "EtPeTool.h"

class Collection;
class PeClassItem;
class PeClassReference;
class Zoomer;

//---- ClassTreeView -----------------------------------------------------------

enum PeCTreeShow {
	ePeCTShowAll,
	ePeCTShowAbstract,
	ePeCTShowApp,
};

class PeClassTreeView: public TreeView {
	Collection *classes;
	Collection *references;
	PeCTreeShow show;

private:
	void SynchSelection();

public:
	MetaDef(PeClassTreeView);
	PeClassTreeView(EvtHandler*, Class *root);
	~PeClassTreeView();

	Command *GetNodeSelector(TreeNode *tn, int cl);
	void OpenTreeNode(TreeNode*, bool mode);

	void ShowClass(Class *cl);
	void ShowAllClasses();
	void ShowOnlyAbstractClasses();
	void ShowOnlyApplicationClasses();
	PeCTreeShow Shows();
	void SetSelection(VObject *gp);

	PeClassItem *FindClassItem(Class*);
	Class *GetRootClass();
	TreeNode *FindTreeNode(VObject *selection);
	void Draw(Rectangle);

	//---- construction
	VObject *NodeAsVObject(Object*);
	Iterator *MakeChildrenIter(Object*);

	//---- menu
	void DoSetupMenu(Menu *menu);
	Command *DoMenuCommand(int cmd);
	MenuBar *DoMakeMenuBar();

	//---- references
	void AddReference(PeClassReference*);
	void RemoveAllReferences();
	void ShowMembers(PeClassItem*);
	void ShowAllClients(PeClassItem*);
};

//---- PeHierarchyBrowser ------------------------------------------------------

class PeHierarchyBrowser: public EtPeTool {
	static PeHierarchyBrowser *hierBrowser;
	PeClassTreeView *ct;
	Zoomer *hierZoomer;
public:
	MetaDef(PeHierarchyBrowser);
	PeHierarchyBrowser(Manager *m, Class *root);
	~PeHierarchyBrowser();
	VObject *DoMakeContent();
	Point GetInitialWindowSize();

	void ShowClass(Class *cp);

	MenuBar *DoMakeMenuBar();
	Command *DoMenuCommand(int cmd);
	void DoSetupMenu(Menu *mp);

	static void Spawn(Manager *m, Class *root);
	static void ShowClass(Manager *m, Class *selection);
};

//---- PeNameTreeNodeSelector --------------------------------------------------

class PeNameTreeNodeSelector: public Command {
	TreeNode *item;
	bool inside, lastinside;
	int clicks;
	const char *name;
	Point p;
	Font *fp;
public:
	PeNameTreeNodeSelector(TreeNode *s, int cl);
	void TrackFeedback(Point, Point, bool);
	Command *TrackMouse(TrackPhase, Point, Point, Point);
};

//---- PeClassReference --------------------------------------------------------

class PeClassReference: public Object {
	PeClassItem *cl;
	Collection *nodes;
	int width;
	Ink *pat;
public:
	PeClassReference(PeClassItem *cl, Collection *n,
											Ink *pat= ePatBlack, int width= 1);
	~PeClassReference();
	Rectangle BBox();
	void Draw(Rectangle);
	bool Includes(PeClassItem*);
	virtual void DrawConnection(PeClassItem *from, PeClassItem *to);
	virtual void CircularReference(PeClassItem *cl);
	virtual void SetWidthAndPattern(PeClassItem *from, PeClassItem *to);
};

//---- PeMemberReference -------------------------------------------------------

class PeMemberReference: public PeClassReference {
public:
	PeMemberReference(PeClassItem *cl, Collection *n);
	void SetWidthAndPattern(PeClassItem *from, PeClassItem *to);
};

#endif

